import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Girl } from './entities/girl.entity';

@Injectable()
export class GirlService {
  constructor(
    // 这个叫做依赖注入
    @InjectRepository(Girl) private readonly girl: Repository<Girl>,
  ) {}

  async getGIDLEGirls() {
    let res = await this.girl.find();
    return res;
  }

  async addGIDLEGirl(girl: Girl) {
    let res = await this.girl.save(girl);
    return res;
  }

  getGIDLEGirlById(id: string): object {
    return this.girl.findOneBy({ id });
  }

  findGIDLEGirlById(id: string): object {
    return this.girl.findOneBy({ id });
  }

  async findAllGIDLEGirls() {
    let res = await this.girl.find();
    return res;
  }

  async findGIDLEGirlsByName(name: string) {
    let res = await this.girl.findBy({ name });
    return res;
  }
}
